function y=local_shuffle(x,c)
% function y=local_shuffle(x,c)
% shuffles locally with in subset, reduces repetition.
% can't have more the 2 in a row.
% x = numbers to shuffle (e.g. 4 trial types)
% c = count of shuffle output (e.g. 40 trials)
% compare:  trial1=shuffle(repmat(1:4,1,10))';
%      to:  trial2=local_shuffle(4,40)';
% [trial1 trial2]
% Percent of repetitions:
% sum(diff(trial1)==0)/length(trial1)*100
% sum(diff(trial2)==0)/length(trial2)*100
%
% ~ bcoe
%
if nargin == 0
    help(mfilename)
    return
end
if length(x)>1% x is a vector of items needed to be shuffeled
    X=x;
    x=length(X);
else
    X=[];
end
    

%floor(c/x);
y=[];
for ii = 1:ceil(c/x)
    y=[y Shuffle(1:x)]; %#ok<*AGROW>
end
y=y(1:c);
if X
    y=X(y);
end


